package com.ayf.payment.game.api.dto.player;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description: 分页查询常用条件
 * @Author: zh-liang
 * @Date : 2020-08-19 15:06
 */
public class MyPageVO implements Serializable {
    private static final long serialVersionUID = 1L;
    private int pageNum;
    private int pageSize;
    private Date startTime;
    private Date endTime;
    private Integer startTimeYear;
    private Integer endTimeYear;
    private Integer startTimeMonth;
    private Integer endTimeMonth;
    private Integer startTimeDay;
    private Integer endTimeDay;

    public int getPageNum() {
        return Math.max(pageNum, 1);
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize > 0 ? pageSize : 10;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
        this.startTimeYear = dateToInteger(startTime, "yyyy");
        this.startTimeMonth = dateToInteger(startTime, "MM");
        this.startTimeDay = dateToInteger(startTime, "dd");
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
        this.endTimeYear = dateToInteger(endTime, "yyyy");
        this.endTimeMonth = dateToInteger(endTime, "MM");
        this.endTimeDay = dateToInteger(endTime, "dd");
    }

    public Integer getStartTimeYear() {
        return startTimeYear;
    }

    public Integer getEndTimeYear() {
        return endTimeYear;
    }

    public Integer getStartTimeMonth() {
        return startTimeMonth;
    }

    public Integer getEndTimeMonth() {
        return endTimeMonth;
    }

    public Integer getStartTimeDay() {
        return startTimeDay;
    }

    public Integer getEndTimeDay() {
        return endTimeDay;
    }

    private Integer dateToInteger(Date generateTime, String formatPattern) {
        if (null == generateTime) {
            return null;
        }
        try {
            return Integer.parseInt(new SimpleDateFormat(formatPattern).format(generateTime));
        } catch (Exception e) {
            return null;
        }
    }
}
